Loops
While <condition> <statements>
EndWhile
While loop will check the
<condition> and if it's true will execute the commands
inside the <statements> block.
Parameters
<condition> Numeric or string expression.
<statements> A block of statements
that are executed when the condition is True.
Remarks
-
You can always break from the loop by giving a Break command.
- Inside the loop, Loop or Continue may be used to bye-pass the remaining statements and move to the next condition in the While loop.
-
The loop is repeated until the condition becomes false. One can have nested While loops also.
Example
1. Simple loop:
:DBUPDATE
// Oracle OLEDB Connection
$db = "Provider=MSDAORA.1;User ID=scott;Password=tiger;Data Source=xtendora;Persist Security Info=False"
// open table EMP (default table in ORACLE)
$empinfo = db.Open($db,"SELECT * FROM EMP")
if $empinfo != 1 then goto DBERROR
// read records one by one using db.Skip
while not $empinfo.eof
display $empinfo.ENAME " " $empinfo.JOB " " $empinfo.SAL
$empinfo = db.Skip()
endwhile
// Close Table
$empinfo = db.Close()
goto MAIN
:DBERROR
;............
;............
2. Loop with Break/Exit and Loop/Continue:
:DBUPDATE
// Oracle OLEDB Connection
$db = "Provider=MSDAORA.1;User ID=scott;Password=tiger;Data Source=xtendora;Persist Security Info=False"
// Run query on table EMP (default table in ORACLE)
$empinfo = db.Open($db,"SELECT * FROM EMP ORDER BY SAL ASC")
if $empinfo != 1 then goto DBERROR
// read records one by one using db.Skip
while not $empinfo.eof
if compare($empinfo.ENAME,"KING") != 0
$empinfo = db.Skip()
continue
endif
display $empinfo.ENAME " " $empinfo.JOB " " $empinfo.SAL
// C,C++ programmers like to use BREAK instead of EXIT
exit
endwhile
// Close Table
$empinfo = db.Close()
:DBERROR
;............
;............